<?php

namespace App\Http\Controllers\Admin;

use AllowDynamicProperties;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Routing\Controller as BaseController;
use Inertia\Inertia;
use Inertia\Response;

#[AllowDynamicProperties]
abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected array $validateMessages = [
        '*' => ':attribute 不合法',
    ];

    public function responseSuccess(): JsonResponse
    {
        return response()->json(['message' => 'success'], 200);
    }

    public function responseCreated($data = []): JsonResponse
    {
        if ($data) {
            return response()->json($data, 201);
        }
        return response()->json(['message' => 'created success'], 201);
    }

    public function responseDeleted(): JsonResponse
    {
        return response()->json(['message' => 'deleted success'], 204);
    }

    public function inertia(string $component, array|Arrayable $props = []): Response
    {
        return Inertia::render($component, $props);
    }
}
